package com.qfjy.common.utils.crypto;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

/**
 * @ClassName AESUtils
 * @Description TODO
 * @Author guoweixin
 * @Date 2022/12/7
 * @Version 1.0
 */
public class AESUtils {

    //开发人员定义密钥
   private static  String keyS="java2204nanjing1";

    /**
     * 加密方法
     */
    public  static  String encryptMethod(String content){
        byte[] key=keyS.getBytes();
        //构建
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);
        //加密
        byte[] encrypt = aes.encrypt(content);
        //加密为16进制表示  c947b179c8f955f00e8c77635cab9196
        String encryptHex = aes.encryptHex(content);


        return encryptHex;
    }

    /**
     * 解密方法
     */
    public static String decryptMethod(String encryptHex){
        byte[] key=keyS.getBytes();
        //构建
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);

        String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);


        return decryptStr;
    }


    public static void main(String[] args) {
       // String content="java2204";

     //  String encryptHex= AESUtils.encryptMethod(content);
     //   System.out.println("加密后的："+encryptHex);  //ff20e2e02523039883799cb2b424cbf9
        String encryptHex="ff20e2e02523039883799cb2b424cbf9";

       String decryptStr= AESUtils.decryptMethod(encryptHex);
        System.out.println("解密后的明文："+decryptStr);
    }

}
